package com.tjetc.usermanage;

import com.tjetc.domian.Communityfee;
import com.tjetc.proxy.ClientProxy;
import com.tjetc.service.FeeService;
import com.tjetc.service.ResidentService;
import com.tjetc.vo.AppData;

import java.math.BigDecimal;
import java.util.List;
import java.util.Scanner;

public class FeeView {
    private Scanner scanner = new Scanner(System.in);
    private FeeService feeService = ClientProxy.getProxyInstance(FeeService.class);
    private ResidentService ResidentService = ClientProxy.getProxyInstance(ResidentService.class);
    public void start() {
        while (true) {
            System.out.println("费用菜单");
            System.out.println("1.查询费用信息");
            System.out.println("2.缴费");
            System.out.println("0.返回上一级");
            switch (scanner.nextInt()) {
                case 1:
                    select();
                    break;
                case 2:
                    pay();
                    break;
                case 0:
                    return;
                default:
                    System.out.println("输入有误，请重新输入");
            }
        }
    }

    private void pay() {
        System.out.println("请输入费用编号");
        int feeid = scanner.nextInt();
        System.out.println("请输入费用金额");
        double money = scanner.nextDouble();
        if (feeService.pay(feeid,money)){
            System.out.println("缴费成功");
        }else {
            System.out.println("缴费失败");
        }
    }

    private void select() {
        int residentId = AppData.getCurrentResidentId();
        int apartmentId = ResidentService.getApartmentId(residentId);
        List<Communityfee> list = feeService.select(apartmentId);
        if (list == null){
            System.out.println("没有数据");
        }else {
            for (Communityfee communityfee : list) {
                System.out.println(communityfee);
            }
        }
    }
}
